package com.declare.ajax;

import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/books")
public class books extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String val = request.getParameter("作者是谁");
        List book = new ArrayList();
        if(val.equals("1")){
            book.add("你");
            book.add("我");
            book.add("他");
        }else if(val.equals("2")){
            book.add("你");
            book.add("我");
            book.add("他");
        }else if(val.equals("3")){
            book.add("你");
            book.add("我");
            book.add("他");
        }
        String json = JSON.toJSONString(book);
        System.out.println(json);
        response.setContentType("books/html;charset=UTF-8");
        response.getWriter().println(json);
    }
}